package com.dadaguai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dadaguai.domain.UserMessage;
import com.dadaguai.dto.SystemDto.SystemSettingDto;
import com.dadaguai.enums.MessageStatusEnum;
import com.dadaguai.enums.MessageTypeEnum;
import com.dadaguai.service.UserMessageService;
import com.dadaguai.mapper.UserMessageMapper;
import com.dadaguai.utils.SysSettingUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 王半仙
* @description 针对表【user_message(用户消息)】的数据库操作Service实现
* @createDate 2023-10-20 11:28:40
*/
@Service
public class UserMessageServiceImpl extends ServiceImpl<UserMessageMapper, UserMessage>
    implements UserMessageService{

    @Autowired
    UserMessageMapper userMessageMapper;
    /**
     * 发送系统消息
     * @param userId 目标用户id
     */
    @Override
    public void sendSysMessage(String userId) {
        UserMessage userMessage = new UserMessage();
        SystemSettingDto sysSettings = SysSettingUtils.getSysSettings();
        userMessage.setReceivedUserId(userId);
        userMessage.setMessageContent(sysSettings.getRegisterSetting().getRegisterWelcomeInfo());
        userMessage.setMessageType(MessageTypeEnum.SYSTEM.getType());
        userMessage.setStatus(MessageStatusEnum.NOT_READ.getStatus());
        userMessage.setCreateTime(new Date());

        userMessageMapper.insert(userMessage);
    }
}




